package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MRecordSignDetailPO;
import com.yiyuan.app.mapper.MRecordSignDetailMapper;
import org.springframework.stereotype.Repository;

@Repository
public class MRecordSignDetailDAO extends BaseDAO<MRecordSignDetailMapper, MRecordSignDetailPO> {


    public MRecordSignDetailPO findAlreadySign(Long userId, Long recordSignId, Integer signDay) {
        LambdaQueryWrapper<MRecordSignDetailPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordSignDetailPO::getUserId, userId);
        queryWrapper.eq(MRecordSignDetailPO::getRecordSignId, recordSignId);
        queryWrapper.eq(MRecordSignDetailPO::getSignDay, signDay);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public MRecordSignDetailPO findLatestAlreadySign(Long userId, Long recordSignId) {
        LambdaQueryWrapper<MRecordSignDetailPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRecordSignDetailPO::getUserId, userId);
        queryWrapper.eq(MRecordSignDetailPO::getRecordSignId, recordSignId);
        queryWrapper.orderByDesc(MRecordSignDetailPO::getId);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }
}
